package blue.datacenter2;


import com.google.gson.Gson;

public class Message {
	public String ip;  // Source IP, where is Message from.
	public String port;  // ID for slave.
	public String data; //
	
	public Message(String json_str){
		try {
			Gson gson = new Gson();
			Message obj = (Message)gson.fromJson(json_str, Message.class);
			this.ip = obj.ip;
			this.port = obj.port;
			this.data = obj.data;
		}catch(Exception e) {
			System.out.println("Error: Failed to parse json > "+json_str);
		}
	}
	
	public Message(String sip, String sport, String msg){
		ip = sip;
		port = sport;
		data = msg;
	}
	
	public String toJSON() {
		Gson gson = new Gson();
		return gson.toJson(this);
	}
}
